import Vue from 'vue'

// 完整引入
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';


import App from './App.vue'
import router from './router';
import store from './store';
import './api/mock.js'
import Cookie from 'js-cookie';


Vue.config.productionTip = false

// 导航守卫
router.beforeEach((to, from, next) => {
  // 判断token是否存在
  const token =Cookie.get('token')
  if(!token && to.name !=='login'){
    next({name:'login'})
  }else if (token && to.name=== 'login'){
    next({name:'home'})
  }else{
    next()
  }
})

Vue.use(ElementUI);
new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')
